<template>
  <div class="framework-container">
    <Background />
    <div class="content-wrapper">
      <!-- 头部部分 -->
      <div class="header-section">
        <div class="left">
          <div class="data-panel left-panel" v-if="isPanel">
            <div class="panel-header">
              <span class="header-text">过程互动数据表</span>
              <div class="header-decoration"></div>
              <div class="header-grid"></div>
            </div>
            <div class="panel-content">
              <el-row :gutter="10" class="data-row" v-if="interactData.length >= 7">
                <el-col :span="8" v-for="(item, index) in interactData.slice(0, 3)" :key="index">
                  <div class="data-item tech-item">
                    <div class="value">{{ item.number }}</div>
                    <div class="label">{{ item.name }}</div>
                    <div class="tech-corner tl"></div>
                    <div class="tech-corner tr"></div>
                    <div class="tech-corner bl"></div>
                    <div class="tech-corner br"></div>
                    <div class="pulse-effect"></div>
                  </div>
                </el-col>
              </el-row>
              <el-row :gutter="10" class="data-row" v-if="interactData.length >= 7">
                <el-col :span="6" v-for="(item, index) in interactData.slice(3, 7)" :key="index + 3">
                  <div class="data-item tech-item">
                    <div class="value">{{ item.number }}</div>
                    <div class="label">{{ item.name }}</div>
                    <div class="tech-corner tl"></div>
                    <div class="tech-corner tr"></div>
                    <div class="tech-corner bl"></div>
                    <div class="tech-corner br"></div>
                    <div class="pulse-effect"></div>
                  </div>
                </el-col>
              </el-row>
            </div>
            <div class="panel-grid"></div>
          </div>
        </div>

        <div class="center-section">
          <div class="title-text">
            <div class="title-button" @click="switchTitle('home')">
              <i class="el-icon-data-analysis"></i>
              总体分析
            </div>
            <div class="title">
              <slot name="title">主要内容区域</slot>
            </div>
            <div class="title-button" @click="switchTitle('index')">
              <i class="el-icon-user"></i>
              学生画像
            </div>
          </div>
          <div class="title-lines">
            <div class="sub-title">专业班级：</div>
            <div class="class-number">
              <span class="number" @click="switchClass">{{ currentTitle }}</span>
            </div>
          </div>
        </div>

        <div class="right">
          <div class="data-panel right-panel" v-if="isPanel">
            <div class="panel-header">
              <span class="header-text">过程互动数据表</span>
              <div class="header-decoration"></div>
              <div class="header-grid"></div>
            </div>
            <div class="panel-content">
              <el-row :gutter="10" class="data-row" v-if="interactData.length >= 12">
                <el-col :span="12" v-for="(item, index) in interactData.slice(7, 9)" :key="index + 7">
                  <div class="data-item tech-item">
                    <div class="value">{{ item.number }}</div>
                    <div class="label">{{ item.name }}</div>
                    <div class="tech-corner tl"></div>
                    <div class="tech-corner tr"></div>
                    <div class="tech-corner bl"></div>
                    <div class="tech-corner br"></div>
                    <div class="pulse-effect"></div>
                  </div>
                </el-col>
              </el-row>
              <el-row :gutter="10" class="data-row" v-if="interactData.length >= 12">
                <el-col :span="8" v-for="(item, index) in interactData.slice(9, 12)" :key="index + 9">
                  <div class="data-item tech-item">
                    <div class="value">{{ item.number }}</div>
                    <div class="label">{{ item.name }}</div>
                    <div class="tech-corner tl"></div>
                    <div class="tech-corner tr"></div>
                    <div class="tech-corner bl"></div>
                    <div class="tech-corner br"></div>
                    <div class="pulse-effect"></div>
                  </div>
                </el-col>
              </el-row>
            </div>
            <div class="panel-grid"></div>
          </div>
        </div>
      </div>

      <!-- 主要内容区域 -->
      <div class="main-content">
         <div class="content">
          <slot></slot>
         </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios';
export default {
  name: 'Teamwork',
  data() {
    return {
      interactData: Array(12).fill({ number: 0, name: '' }),
      // 专业班级数据
      classes: [],
      currentClass: this.$store.state.current,
      currentTitle: null,
      isPanel: this.$route.name === 'home' // 初始化时根据当前路由设置
    };
  },
  created() {
    this.fetchClassList();
  },
  mounted() {
    this.fetchInteractData();
    // 添加路由监听
    this.$watch(
      () => this.$route,
      (to) => {
        this.isPanel = to.name === 'home';
      }
    );
  },
  methods: {
    async fetchInteractData() {
      try {
        const response = await axios.get('/group/allInteractRecords');
        if (response.data.errno === 0) {
          this.interactData = response.data.data;
        }
      } catch (error) {
        console.error('获取互动数据失败', error);
      }
    },
    // 获取班级列表
    async fetchClassList() {
      try {
        const response = await this.$axios.get('/class/list');
        if (response.data.errno === 0) {
          this.classes = response.data.data;
          this.updateCurrentTitle();
        }
      } catch (error) {
        console.error('获取班级列表失败:', error);
      }
    },
    // 更新当前标题
    updateCurrentTitle() {
      const currentClass = this.classes.find(c => c.studentClassId === this.currentClass);
      if (currentClass) {
        this.currentTitle = currentClass.className;
      }
    },
    // 切换班级方法
    switchClass() {
      // 找到当前班级的索引
      const currentIndex = this.classes.findIndex(c => c.studentClassId === this.currentClass);
      // 计算下一个班级的索引
      const nextIndex = (currentIndex + 1) % this.classes.length;
      // 更新当前班级
      this.currentClass = this.classes[nextIndex].studentClassId;
      // 传递当前班级到vuex中
      this.$store.commit('updateCurrentClass', this.currentClass);
      // 更新标题
      this.updateCurrentTitle();
    },
    switchTitle(name) {
      // 判断当前路由是否与目标路由相同
      if (this.$route.name !== name) {
        // 页面跳转
        this.$router.push({ name: name })
      }
      // 切换标题
      // 添加标题切换动画类
      const titleEl = document.querySelector('.title-text')
      titleEl.classList.add('title-fade')
      // 动画结束后移除动画类
      setTimeout(() => {
        titleEl.classList.remove('title-fade')
      }, 300)
    }
  }
};
</script>

<style scoped>
/* 基础框架样式 */
.framework-container {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
}

.content-wrapper {
  position: relative;
  z-index: 1;
  margin: 0 auto;
  width: 98%;
  height: 100%;
}

.header-section {
  width: 100%;
  height: 20%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
}

.main-content {
  margin-top: 5px;
  width: 100%;
  height: 78%;
  display: flex;
  justify-content: center;
}
.content{
  width: 100%;
  height: 100%;
}
/* 头部中间部分 */
.center-section {
  width: 45%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.title {
  width: 70%;
  height: 60%;
  background-image: url('@/assets/title_bg.png');
  background-size: 100% 100%;
  background-position: center;
  background-repeat: no-repeat;
  color: #00ffff;
  font-weight: bold;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.title-text {
  height: 60%;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.title-button {
  width: 12%;
  height: 30%;
  background: rgba(0, 20, 40, 0.6);
  border: 1px solid #00ffff;
  border-radius: 2px;
  color: #00ffff;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  text-shadow: 0 0 5px rgba(0, 255, 255, 0.5);
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(3px);
}

.title-button::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg,
      rgba(0, 255, 255, 0),
      rgba(0, 255, 255, 0.2),
      rgba(0, 255, 255, 0));
  transition: left 0.5s ease;
}

.title-button:hover::before {
  left: 100%;
}

.title-button:hover {
  background: rgba(0, 255, 255, 0.1);
  box-shadow: 0 0 8px rgba(0, 255, 255, 0.3);
}

.title-button.left {
  left: -100px;
  position: absolute;
}

.title-button.right {
  right: -100px;
  position: absolute;
}

.title-button i {
  margin-right: 10px;
  font-size: 12px;
}

.title-lines {
  width: 100%;
  height: 30%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.sub-title {
  font-size: 20px;
  color: #00ffff;
  text-shadow: 0 0 5px rgba(0, 255, 255, 0.5);
  position: relative;
  font-weight: 500;
  margin: 0;
  padding: 0;
}

.class-number {
  width: 100%;
  height: 40px;
  line-height: 40px;
  background: rgba(0, 20, 40, 0.3);
  border: 1px solid rgba(0, 160, 233, 0.3);
  border-radius: 2px;
  padding: 4px 10px;
  margin: 0;
  width: fit-content;
  position: relative;
  backdrop-filter: blur(1px);
  cursor: pointer;
  transition: all 0.3s ease;
}

.class-number::before,
.class-number::after {
  content: '';
  position: absolute;
  width: 2px;
  height: 2px;
  background: #00ffff;
  box-shadow: 0 0 4px rgba(0, 255, 255, 0.8);
}

.class-number::before {
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
}

.class-number::after {
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
}

.class-number:hover {
  transform: scale(1.05);
  text-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
}

.number {
  font-size: 20px;
  color: #00ffff;
  text-shadow: 0 0 5px rgba(0, 255, 255, 0.5);
  letter-spacing: 1px;
  font-weight: 500;
  position: relative;
  display: inline-block;
  padding: 0 5px;
  background: linear-gradient(180deg,
      rgba(0, 255, 255, 1) 0%,
      rgba(0, 160, 233, 1) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: textShine 3s linear infinite;
}

.number::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg,
      transparent,
      rgba(0, 255, 255, 0.5),
      transparent);
  transform: scaleX(0);
  transition: transform 0.3s ease;
}

.number:hover::after {
  transform: scaleX(1);
}

@keyframes textShine {
  0% {
    filter: hue-rotate(0deg);
  }

  100% {
    filter: hue-rotate(360deg);
  }
}

/* 高级科技感数据面板样式 */
.left,.right{
  width: 18%;
  height: 90%;
}
.data-panel {
  width: 100%;
  height: 100%;
  background: rgba(0, 20, 40, 0.7);
  border: 1px solid rgba(0, 255, 255, 0.3);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 20px rgba(0, 180, 255, 0.3);
  transition: all 0.3s ease;
}

.data-panel:hover {
  box-shadow: 0 0 30px rgba(0, 200, 255, 0.5);
  transform: translateY(-2px);
}

.data-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0, 255, 255, 0.8), transparent);
  animation: scanline 3s linear infinite;
}

.data-panel::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0, 255, 255, 0.8), transparent);
}

.left-panel {
  margin-left: 10px;
}

.right-panel {
  margin-right: 10px;
}

.panel-header {
  height: 15%;
  color: #00ffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0 10px;
  overflow: hidden;
}

.header-text {
  font-size: 16px;
  font-weight: bold;
  text-shadow: 0 0 8px #00ffff, 0 0 16px #00aaff;
  z-index: 2;
  letter-spacing: 1px;
  position: relative;
}

.header-decoration {
  position: absolute;
  bottom: 0;
  width: 80%;
  height: 1px;
  background: linear-gradient(90deg, transparent, #00ffff, transparent);
  box-shadow: 0 0 5px #00ffff;
}

.header-grid {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    linear-gradient(90deg, rgba(0, 255, 255, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(0, 255, 255, 0.05) 1px, transparent 1px);
  background-size: 10px 10px;
  opacity: 0.5;
}

.panel-content {
  width: 100%;
  height: 85%;
  padding: 8px;
  box-sizing: border-box;
  position: relative;
}

.panel-grid {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    linear-gradient(90deg, rgba(0, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(rgba(0, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 15px 15px;
  pointer-events: none;
}

.data-row {
  height: 50%;
  margin: 0 !important;
}

.data-item {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 40, 80, 0.4);
  border: 1px solid rgba(0, 255, 255, 0.2);
  border-radius: 2px;
  margin: 2px;
  position: relative;
  transition: all 0.3s ease;
  overflow: hidden;
  padding: 5px 0;
}

.data-item:hover {
  background: rgba(0, 60, 120, 0.6);
  box-shadow: 0 0 15px rgba(0, 200, 255, 0.4);
  transform: translateY(-3px);
}

.tech-item {
  background: linear-gradient(135deg, rgba(0, 40, 80, 0.4), rgba(0, 20, 40, 0.6));
}

.tech-corner {
  position: absolute;
  width: 10px;
  height: 10px;
  border-color: #00ffff;
  border-style: solid;
  border-width: 0;
  transition: all 0.3s ease;
}

.data-item:hover .tech-corner {
  border-color: #00ffcc;
}

.tl {
  top: 0;
  left: 0;
  border-top-width: 2px;
  border-left-width: 2px;
}

.tr {
  top: 0;
  right: 0;
  border-top-width: 2px;
  border-right-width: 2px;
}

.bl {
  bottom: 0;
  left: 0;
  border-bottom-width: 2px;
  border-left-width: 2px;
}

.br {
  bottom: 0;
  right: 0;
  border-bottom-width: 2px;
  border-right-width: 2px;
}

.pulse-effect {
  position: absolute;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, rgba(0, 255, 255, 0.1) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.5s ease;
}

.data-item:hover .pulse-effect {
  opacity: 1;
  animation: pulse 2s infinite;
}

.value {
  font-weight: bold;
  font-size: 22px;
  color: #ffffff;
  margin-bottom: 2px;
  text-shadow: 0 0 8px #00ffff;
  font-family: 'Arial', sans-serif;
  position: relative;
  z-index: 2;
}

.label {
  font-size: 12px;
  color: #00ffff;
  text-shadow: 0 0 5px #00aaff;
  letter-spacing: 1px;
  position: relative;
  z-index: 2;
}

/* 动画效果 */
@keyframes scanline {
  0% {
    transform: translateY(-100%);
  }

  100% {
    transform: translateY(100%);
  }
}

@keyframes pulse {
  0% {
    transform: scale(0.95);
    opacity: 0.5;
  }

  50% {
    transform: scale(1.05);
    opacity: 0.2;
  }

  100% {
    transform: scale(0.95);
    opacity: 0.5;
  }
}

/* 响应式调整 */
@media (max-width: 1200px) {
  .value {
    font-size: 18px;
  }

  .label {
    font-size: 10px;
  }

  .header-text {
    font-size: 14px;
  }
}
</style>